<template>
    <view>
        <view class="box">
            <view class="h2">举报对象</view>
            <view class="dd photo_s">
                <image mode="aspectFill" :src="U.photo_m_url"></image>
                <view class="h3">
                    {{ U.nickname }}　
                    <text class="span">ID：{{ U.uid }}</text>
                </view>
                <view class="h6">{{ U.sex }}　{{ U.age }}　{{ U.areatitle }}</view>
            </view>
        </view>
        <form @submit="submitFn">
            <view class="box">
                <view class="h2">举报内容</view>
                <view class="rdo">
                    <radio-group class="checkbox2" name="kind">
                        <label class="a" v-for="(item, index) in kind" :key="index">
                            <radio :color="color" :value="item"></radio>
                            {{ item }}
                        </label>
                    </radio-group>
                </view>
            </view>
            <view class="box">
                <view class="h2">举报截图</view>
                <view
                    @tap="upFn"
                    class="i add ico"
                    :style="
                        'color:                                                                                   rgba(' +
                        rgbcolor +
                        ',.6);border-color:rgba(' +
                        rgbcolor +
                        ',.2);background-color:rgba(' +
                        rgbcolor +
                        ',.1)'
                    "
                >
                    <block v-if="globalUtils.empty(path_b)">
                        
                        <text class="h5" :style="'color:rgba(' + rgbcolor + ',.6)'">点击上传</text>
                    </block>
                    <image mode="aspectFill" :src="path_b_url" v-else></image>
                    <input name="path_b" :value="path_b" />
                </view>
            </view>
            <view class="box">
                <view class="h2">详细描述</view>
                <textarea class="textarea" maxlength="1000" name="content" :placeholder="U.tips1"></textarea>
                <view class="em">{{ U.tips2 }}</view>
            </view>
            <view class="nextbtn" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
                <button class="btn5" data-idx="2" formType="submit">立即提交</button>
            </view>
        </form>
        <view class="blank"></view>
    </view>
</template>
<script>
import globalUtils from "../../res/www.a9a.cn";

var t = require('../../res/www.a9a.cn.js');
var app = getApp();
var a = uni.getStorageSync('COOK_U');
export default {
  computed: {
    globalUtils() {
      return globalUtils
    }
  },
    data() {
        return {
            uid: 0,
            path_b_url: '',
            color: '',
            rgbcolor: '',

            U: {
                photo_m_url: '',
                uid: '',
                sex: '',
                age: '',
                areatitle: '',
                tips1: '',
                tips2: ''
            },

            kind: '',
            photo_s: '',
            path_b: ''
        };
    },
    onLoad: function (a) {
        var i = a.uid;
        var that = this;
        app.globalData.get_config('_ZEAI').then(function (a) {
            that.setData({
                color: app.globalData._ZEAI.color,
                rgbcolor: t.c16_rgb(app.globalData._ZEAI.color)
            });
        });
        if (t.ifint(i)) {
            this.setData({
                uid: i
            });
            app.globalData.get_openid().then(function (t) {
                that.init();
            });
        } else {
            uni.showModal({
                content: '用户ID参数错误',
                confirmColor: that.color,
                confirmText: '朕知道了',
                showCancel: false,
                success: function (t) {}
            });
        }
    },
    methods: {
        init: function () {
            var that = this;
            a = uni.getStorageSync('COOK_U');
            uni.showLoading({
                title: '玩命加载中',
                mask: true
            });
            app.globalData.ajax({
                url: '315.php',
                data: {
                    submitok: 'init',
                    uid: that.uid,
                    openid: a.openid
                },
                success: function (o) {
                    if (1 == o.flag) {
                        that.setData({
                            U: o.U,
                            kind: o.kind
                        }),
                            uni.setNavigationBarTitle({
                                title: o.nTitle
                            });
                    } else {
                        (o.this = that), t.sorry(o);
                    }
                    uni.hideLoading();
                }
            });
        },

        submitFn: function (i) {
            var that = this;
            var e = i.detail.value;
            app.globalData.empty(e.kind)
                ? uni.showToast({
                      title: '请选择【举报内容】',
                      icon: 'none',
                      mask: true
                  })
                : app.globalData.empty(e.content)
                ? uni.showToast({
                      title: '请输入【详细描述】',
                      icon: 'none',
                      mask: true
                  })
                : (uni.showLoading({
                      title: '正在保存',
                      mask: true
                  }),
                  app.globalData.ajax({
                      url: '315.php',
                      data: {
                          submitok: 'add_update',
                          openid: a.openid,
                          uid: that.uid,
                          kind: e.kind,
                          content: e.content,
                          path_b: e.path_b
                      },
                      success: function (o) {
                          1 == o.flag
                              ? uni.showModal({
                                    content: o.msg,
                                    confirmColor: that.color,
                                    confirmText: '朕知道了',
                                    showCancel: false,
                                    success: function (t) {
                                        uni.navigateBack();
                                    }
                                })
                              : ((o.this = that), (o.url = 'no'), t.sorry(o));
                          uni.hideLoading();
                      }
                  }));
        },

        upFn: function () {
            var that = this;
            uni.chooseMedia({
                count: 1,
                mediaType: ['image'],
                sourceType: ['album', 'camera'],
                sizeType: ['compressed'],
                success: function (n) {
                    that.setData({
                        photo_s: n.tempFiles[0].tempFilePath
                    });
                    uni.uploadFile({
                        url: app.globalData.WWW + '/api/wxxcx/315.php',
                        filePath: n.tempFiles[0].tempFilePath,
                        name: 'pic',
                        formData: {
                            submitok: 'up',
                            openid: a.openid,
                            uid: that.uid
                        },
                        success: function (o) {
                            1 == (o = t.jsoneval(o.data)).flag
                                ? that.setData({
                                      path_b: o.path_b,
                                      path_b_url: o.path_b_url
                                  })
                                : uni.showModal({
                                      content: o.msg,
                                      confirmColor: that.color,
                                      confirmText: '朕知道了',
                                      showCancel: false,
                                      success: function (t) {}
                                  });
                        }
                    });
                }
            });
        }
    }
};
</script>
<style>
@import '315.css';
</style>
